package com.atguigu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author superHao
 * @date 2022/12/08
 * <p>
 * 使用RESTFul模拟用户资源的增删改查
 * /user        Get     查询所有用户信息
 * /user/1      Get     根据用户id查询用户信息
 * /user        POST    添加用户信息
 * /user/1      DELETE  删除用户信息
 * /user/1      PUT     更新用户信息
 */
@Controller
public class UserController {
    /**
     * @return {@link String}
     */
    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public String getAllUser() {
        System.out.println("查询所有用户信息");
        return "success";
    }

    /**
     * @param id
     * @return {@link String}
     */
    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    public String getUserById(@PathVariable String id) {
        System.out.println("根据id查询用户信息,id=" + id);
        return "success";
    }

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public String insertUser(String username, String password) {
        System.out.println("添加用户信息:" + username + "," + password);
        return "success";
    }

    @RequestMapping(value = "/user/{id}", method = RequestMethod.PUT)
    public String updateUser(@PathVariable String id, String username, String password) {
        System.out.println("修改用户信息id=" + id + ":" + username + "," + password);
        return "success";
    }
}
